var Bow = new Array()
var ls = 0
var key = 0;
for (var i=1; i<=100;i++){
	var key = (Math.random()*11)
	if(key <= 3){
		Bow[i] = "-1"
		ls++
	}else{
		Bow[i] = "0"
	}
}
var lei = document.getElementById("lei")
lei.innerHTML="去战斗吧，请小心！雷总数："+ Number(ls)
console.log(Bow)
//<td><button style="background-color: dimgray;" onclick="Click()">N</button></td>
for(i = 1 ; i<=10;i++){
	var tr = document.getElementById(i);
	for(var ii = 1;ii<=10;ii++){
		var td = document.createElement("td")
		var btn = document.createElement("button");   
		btn.setAttribute("onclick", "Click("+(Number(i-1)*10+Number(ii))+");"); 
		btn.setAttribute("id",i*10+ii)
		btn.setAttribute("class","btn")
		btn.innerHTML = "N"
		td.appendChild(btn)
		tr.appendChild(td)
	}
}
function Click(i){
	console.log(i)
	var id = i+10
	var ls =0
	if(Bow[i]==-1){
		console.log(1)
		var alert = document.getElementById("alert")
		alert.innerHTML="你踩到地雷了,噗"
		var block = document.getElementById(id)
		block.innerHTML="雷"
		block.setAttribute("class","lei")
	}else{
			if (Bow[i-1] == -1) {
				ls = ls+1
			}
			if (Bow[i+1] == -1) {
				ls = ls+1
			}
			if (Bow[i+10] == -1) {
				ls = ls+1
			}
			if (Bow[i+11] == -1) {
				ls = ls+1
			}
			if (Bow[i+9] == -1) {
				ls = ls+1
			}
			if (Bow[i-10] == -1) {
				ls = ls+1
			}
			if (Bow[i-11] == -1) {
				ls = ls+1
			}
			if (Bow[i-9] == -1) {
				ls = ls+1
			}
			var block = document.getElementById(id)
			block.innerHTML=ls
	}
}
function sreload(){
	location.reload();
}